/*     */ package com.zimbra.cs.service.admin;
/*     */ 
/*     */ import com.zimbra.common.account.Key.CosBy;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.soap.AdminConstants;
/*     */ import com.zimbra.common.soap.Element;
/*     */ import com.zimbra.common.util.Log;
/*     */ import com.zimbra.common.util.ZimbraLog;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.account.AccountServiceException;
/*     */ import com.zimbra.cs.account.Cos;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.cs.account.accesscontrol.AdminRight;
/*     */ import com.zimbra.cs.account.accesscontrol.Rights.Admin;
/*     */ import com.zimbra.cs.account.accesscontrol.TargetType;
/*     */ import com.zimbra.soap.JaxbUtil;
/*     */ import com.zimbra.soap.ZimbraSoapContext;
/*     */ import com.zimbra.soap.admin.message.CreateAccountRequest;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class CreateAccount
/*     */   extends AdminDocumentHandler
/*     */ {
/*     */   public boolean domainAuthSufficient(Map context)
/*     */   {
/*  46 */     return true;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */   public boolean defendsAgainstDelegateAdminAccountHarvesting()
/*     */   {
/*  54 */     return true;
/*     */   }
/*     */   
/*     */   public Element handle(Element request, Map<String, Object> context) throws ServiceException
/*     */   {
/*  59 */     ZimbraSoapContext zsc = getZimbraSoapContext(context);
/*  60 */     Provisioning prov = Provisioning.getInstance();
/*  61 */     CreateAccountRequest req = (CreateAccountRequest)JaxbUtil.elementToJaxb(request);
/*     */     
/*  63 */     String name = req.getName().toLowerCase();
/*  64 */     Map<String, Object> attrs = req.getAttrsAsOldMultimap(true);
/*     */     
/*  66 */     checkDomainRightByEmail(zsc, name, Rights.Admin.R_createAccount);
/*  67 */     checkSetAttrsOnCreate(zsc, TargetType.account, name, attrs);
/*  68 */     checkCos(zsc, attrs);
/*     */     
/*  70 */     Account account = prov.createAccount(name, req.getPassword(), attrs);
/*     */     
/*  72 */     ZimbraLog.security.info(ZimbraLog.encodeAttrs(new String[] { "cmd", "CreateAccount", "name", name }, attrs));
/*     */     
/*  74 */     Element response = zsc.createElement(AdminConstants.CREATE_ACCOUNT_RESPONSE);
/*  75 */     ToXML.encodeAccount(response, account);
/*  76 */     return response;
/*     */   }
/*     */   
/*     */   private void checkCos(ZimbraSoapContext zsc, Map<String, Object> attrs) throws ServiceException {
/*  80 */     String cosId = ModifyAccount.getStringAttrNewValue("zimbraCOSId", attrs);
/*  81 */     if (cosId == null) {
/*  82 */       return;
/*     */     }
/*     */     
/*  85 */     Provisioning prov = Provisioning.getInstance();
/*     */     
/*  87 */     Cos cos = prov.get(Key.CosBy.id, cosId);
/*  88 */     if (cos == null) {
/*  89 */       throw AccountServiceException.NO_SUCH_COS(cosId);
/*     */     }
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*  95 */     checkRight(zsc, cos, Rights.Admin.R_assignCos);
/*     */   }
/*     */   
/*     */   public void docRights(List<AdminRight> relatedRights, List<String> notes)
/*     */   {
/* 100 */     relatedRights.add(Rights.Admin.R_createAccount);
/*     */     
/* 102 */     notes.add(String.format("All attrs provided in the attribute list have to settable by. the authed admin.   You can grant the %s right, which allows setting all attributes on %s, or grant the set attrs right just for the attributes the admin needs to set while creating an entry.", new Object[] { Rights.Admin.R_modifyAccount.getName(), "account" }));
/*     */     
/*     */ 
/* 105 */     notes.add("Notes on zimbraCOSId: If setting zimbraCOSId, needs the " + Rights.Admin.R_assignCos.getName() + " right on the cos.");
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/service/admin/CreateAccount.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */